#ifndef ACTIONMODEL_H
#define ACTIONMODEL_H

#include <QAbstractListModel>
#include "action.h"
#include "animationdatahandler.h"
#include <QItemSelection>
#include <QDebug>

class ActionModel : public QAbstractListModel
{
    Q_OBJECT

public:
    ActionModel(AnimationDataHandler* coreData, QObject* parent = 0);
    ~ActionModel();

    QVariant data(const QModelIndex &index, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                                int role = Qt::DisplayRole) const;

    bool setData(const QModelIndex &index, const QVariant &value, int role);
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    void appendNewAction();
    void deleteAction(QModelIndex& index);

    QModelIndex getCurrentActionIndex();


signals:
    void notifyDataUpdatError();

public slots:
    void selectChanged(const QItemSelection& selected,const QItemSelection& desSelected);
    void dataChangeUpdate();


private:
     bool isValidIndex(const QModelIndex& index) const;
     QVariant getColumnData(int section, Action* action) const;
     bool setDataByColumnIndex(int section, Action* action,const QVariant& value);
     int getOverZeroValue(int value);

private:
     static const int MAX_COLUMN_NUM;

private:
    AnimationDataHandler* m_coreData;
};

#endif // ACTIONMODEL_H
